<?php

namespace App\Http\Controllers;

use App\Service\DicsService;
use App\Validation\ListValidation;
use App\Validation\DicsTreeValidation;
use App\Validation\DicsSearchValidation;

class DicsController extends BaseController
{

	/**
	 * [indexAction 获取列表]
	 * @return [type] [description]
	 */
	public function indexAction()
	{
		$raw = $this->validation(new ListValidation, $this->request->getJsonRawBody());
		
		$data = DicsService::getList($raw);
		$count = DicsService::getList($raw, TRUE);

		$assign = [
			'total' => $count,
			'list'  => $data
		];

		return $this->echoJson($assign);
	}

	/**
	 * [detailAction 推荐详情]
	 * @return [type] [description]
	 */
	public function detailAction()
	{
		$id = $this->dispatcher->getParam('id');
		$data = DicsService::getInfo($id);

		return $this->echoJson($data);
	}

	/**
	 * [treeAction 获取字典树型结构]
	 * @return [type] [description]
	 */
	public function treeAction()
	{
		$raw = $this->validation(new DicsTreeValidation, $this->request->getJsonRawBody());
		$raw->city_id = $this->city_id;
		$data = DicsService::getTree($raw);
		return $this->echoJson($data);
	}

	public function subsAction()
	{
		$raw = $this->validation(new DicsSearchValidation, $this->request->getJsonRawBody());
		$data = DicsService::getSubsSelect($raw);

		return $this->echoJson($data);
	}

	public function selectAction()
	{
		$raw = $this->validation(new DicsSearchValidation, $this->request->getJsonRawBody());
		$data = DicsService::getSelect($raw);

		return $this->echoJson($data);
	}
}